//
//  AY_DirectoryCell.m
//  AiYue
//
//  Created by boWen on 2023/11/20.
//

#import "AY_DirectoryCell.h"

@interface AY_DirectoryCell ()
@property (nonatomic, strong) UILabel * chapterLabel;
@property (nonatomic, strong) UIImageView * lockImg;
@end

@implementation AY_DirectoryCell


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self addAllSubviewsWithUI];
    }
    return self;
}


- (void)addAllSubviewsWithUI {
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    self.contentView.backgroundColor = COLOR_Bg;
    
    UIView * bg_View = [AYTool createViewWithFrame:CGRectZero andBg:[UIColor whiteColor] andRadius:YNUM(6) andAddSubView:self.contentView];
    [bg_View mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.bottom.equalTo(self.contentView);
    }];
    
    self.lockImg = [AYTool createImageViewWithFrame:CGRectZero andImage:YImage(@"AY_lock") andBg:nil andRadius:YNUM(4) andAddSubView:bg_View];
    [self.lockImg mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(YNUM(20));
        make.width.mas_equalTo(YNUM(20));
        make.right.equalTo(bg_View.mas_right).offset(YNUM(-12));
        make.centerY.equalTo(bg_View);
    }];
    
    self.chapterLabel = [AYTool createLabelWithFrame:CGRectZero andText:nil andTextColor:COLOR_BLACK andBgColor:nil andFont:YFont(14) andLines:1 andRadius:0 andAddSubView:bg_View];
    [self.chapterLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(bg_View);
        make.left.equalTo(bg_View.mas_left).offset(YNUM(16));
        make.right.equalTo(self.lockImg.mas_right).offset(YNUM(-10));
        make.height.offset(YNUM(24));
    }];
    
}

- (void)setChapterModel:(ReadChapterModel *)chapterModel {
    _chapterModel = chapterModel;
    self.chapterLabel.text = kStringUtils(_chapterModel.title);
    if([kStringUtils(_chapterModel.chargeFlag) isEqualToString:@"1"]) {
        self.lockImg.hidden = NO;
    }else {
        self.lockImg.hidden = YES;
    }
}


@end
